home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / AmiVoGL_MDEV.lha / src / tensor.c < prev    next >
C/C++ Source or Header  |  1994-04-12  |  2KB  |  101 lines

  1. #include "vogl.h"
  2.  
  3. /*
  4.  *  premulttensor
  5.  *
  6.  *  Premultiply the tensor b by the matrix a and place the result
  7.  *  into the tensor c.
  8.  */
  9. void premulttensor(
  10.   Tensor c,
  11.   Matrix a,
  12.   Tensor b)
  13. {
  14. register    int    i, j, k;
  15. float        x1, x2, x3, x4;
  16.  
  17. for (i = 0; i < 4; i++)
  18. for (j = 0; j < 4; j++) {
  19.     x1 = x2 = x3 = x4 = 0.0;
  20.     for (k = 0; k < 4; k++) {
  21.         x1 += a[i][k] * b[0][k][j];
  22.         x2 += a[i][k] * b[1][k][j];
  23.         x3 += a[i][k] * b[2][k][j];
  24.         x4 += a[i][k] * b[3][k][j];
  25.         }
  26.     c[0][i][j] = x1;
  27.     c[1][i][j] = x2;
  28.     c[2][i][j] = x3;
  29.     c[3][i][j] = x4;
  30.     }
  31. }
  32.  
  33. /* ------------------------------------------------------------------------ */
  34.  
  35. /*
  36.  *  multtensor
  37.  *
  38.  *  Multiply the tensor b by the matrix a and place the result
  39.  *  into the tensor c.
  40.  */
  41. void multtensor(
  42.   Tensor c,
  43.   Matrix a,
  44.   Tensor b)
  45. {
  46. register    int    i, j, k;
  47. float        x1, x2, x3, x4;
  48.  
  49. for (i = 0; i < 4; i++)
  50. for (j = 0; j < 4; j++) {
  51.     x1 = x2 = x3 = x4 = 0.0;
  52.     for (k = 0; k < 4; k++) {
  53.         x1 += b[0][i][k] * a[k][j];
  54.         x2 += b[1][i][k] * a[k][j];
  55.         x3 += b[2][i][k] * a[k][j];
  56.         x4 += b[3][i][k] * a[k][j];
  57.         }
  58.     c[0][i][j] = x1;
  59.     c[1][i][j] = x2;
  60.     c[2][i][j] = x3;
  61.     c[3][i][j] = x4;
  62.     }
  63. }
  64.  
  65. /* ------------------------------------------------------------------------ */
  66.  
  67. /*
  68.  * Copy the tensor a into b.
  69.  */
  70. void copytensor(
  71.   Tensor b,
  72.   Tensor a)
  73. {
  74. register    int    i, j, k;
  75.  
  76. for (i = 0; i < 4; i++)
  77. for (j = 0; j < 4; j++)
  78. for (k = 0; k < 4; k++)
  79. b[i][j][k] = a[i][j][k];
  80. }
  81.  
  82. /* ------------------------------------------------------------------------ */
  83.  
  84. /*
  85.  * Copy the tensor a into b "transposed".
  86.  */
  87. void copytensortrans(
  88.   Tensor b,
  89.   Tensor a)
  90. {
  91. register    int    i, j, k;
  92.  
  93. for (i = 0; i < 4; i++)
  94. for (j = 0; j < 4; j++)
  95. for (k = 0; k < 4; k++)
  96. b[i][j][k] = a[i][k][j];
  97. }
  98.  
  99. /* ------------------------------------------------------------------------ */
  100.  
  101.